<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>我的待办</title>
    <link rel="stylesheet" href='/plug-in/pear/css/pear.css' media="all">
    <link rel="stylesheet" href='/css/base.css'>
</head>
<body>
<div class="page-content">
    <table class = "layui-hide" id = "table" lay-filter = "table"></table>
</div>

<script type = "text/html" id = "toolbarTop">
    <div class = "layui-btn-container">
        <button class = "layui-btn layui-btn-sm layui-bg-black" lay-event = "refresh">
            <span class = "fa fa-refresh" title = "刷新表格" aria-hidden = "true"></span>
        </button>
    </div>
</script>
<script type = "text/html" id = "barRight">
    <a class = "layui-btn layui-btn-xs" lay-event = "list">申请单</a>
    <!--<a class = "layui-btn layui-btn-xs layui-btn-warm" lay-event = "ok">同意</a>-->
    <!--<a class = "layui-btn layui-btn-xs layui-btn-danger" lay-event = "no">拒绝</a>-->
</script>
<script src="/plug-in/jquery/jquery-3.5.1.min.js" charset="utf-8"></script>
<script src='/plug-in/layui/layui.js' charset="utf-8"></script>
<script type="text/javascript" >
    let form = layui.form, layer=layui.layer, table = layui.table;

    let tab = table.render({
        elem: '#table',
        url: '/activities/my/tasks',
        //page: {
        //    layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
        //    groups: 3, //只显示 1 个连续页码
        //},
        height: "full-45",
        limit: 30,
        skin: "line",
        limits: [30, 45, 60],
        toolbar: '#toolbarTop', //开启头部工具栏，并为其绑定左侧模板
        //defaultToolbar: null,
        parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "total": res.data.length, //解析数据长度
                "data": res.data //解析数据列表
            };
        },
        response: {
            statusCode: 200, //规定成功的状态码，默认：0
            countName: 'total' //规定数据总数的字段名称，默认：count
        },
        cols: [[
            {field: "name", minWidth: 120, title: '流程名称'},
            {field: "user", minWidth: 120, title: '发起用户'},
            {field: "business", minWidth: 120, title: '发起业务'},
            {field: "startTime", minWidth: 120, title: '开始时间'},
            {title: '操作', toolbar: '#barRight', width: 200, unresize: true, fixed: 'right'}]
        ]
    });

    table.on('toolbar(table)', function(obj) {
        var checkStatus = table.checkStatus(obj.config.id);
        switch (obj.event) {
            case 'refresh':
                tab.reload()
                break;
        }
    });


    table.on('tool(table)', function(obj) {
        var data = obj.data;
        if (obj.event==="list"){
            layer.open({
                type: 2,
                content: "/page/business/form/"+data.processDefinitionId+"/"+data.processInstanceId,
                title: false,
                area: ["60%", "80%"],
                scrollbar: false,
                btn: ['同意', '拒绝'],
                yes: function () {
                    $.get("/activities/do/"+data.id+"/true", (res)=>{
                        tab.reload()
                        layer.closeAll()
                    })
                },
                btn2: function () {
                    $.get("/activities/do/"+data.id+"/false", (res)=>{
                        tab.reload()
                        layer.closeAll()
                    })
                    return false
                }
            })
        }
    });
</script>
</body>
</html>